home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBDde / HTBDDE.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  7.1 KB  |  339 lines

  1. // HTBDDE.cpp : Defines the initialization routines for the DLL.
  2. //
  3.  
  4. /////////////////////////////////////////////////////////////////////////////
  5. // Includes
  6. //
  7. #include "stdafx.h"
  8. #include "mfcdde.h"
  9. #include "HTBDDE.h"
  10.  
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. //
  19. //    Note!
  20. //
  21. //        If this DLL is dynamically linked against the MFC
  22. //        DLLs, any functions exported from this DLL which
  23. //        call into MFC must have the AFX_MANAGE_STATE macro
  24. //        added at the very beginning of the function.
  25. //
  26. //        For example:
  27. //
  28. //        extern "C" BOOL PASCAL EXPORT ExportedFunction()
  29. //        {
  30. //            AFX_MANAGE_STATE(AfxGetStaticModuleState());
  31. //            // normal function body here
  32. //        }
  33. //
  34. //        It is very important that this macro appear in each
  35. //        function, prior to any calls into MFC.  This means that
  36. //        it must appear as the first statement within the 
  37. //        function, even before any object variable declarations
  38. //        as their constructors may generate calls into the MFC
  39. //        DLL.
  40. //
  41. //        Please see MFC Technical Notes 33 and 58 for additional
  42. //        details.
  43. //
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CHtbDdeApp
  47.  
  48. BEGIN_MESSAGE_MAP(CHtbDdeApp, CWinApp)
  49.     //{{AFX_MSG_MAP(CHtbDdeApp)
  50.         // NOTE - the ClassWizard will add and remove mapping macros here.
  51.         //    DO NOT EDIT what you see in these blocks of generated code!
  52.     //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CHtbDdeApp construction
  57.  
  58. CHtbDdeApp::CHtbDdeApp()
  59. {
  60.     // TODO: add construction code here,
  61.     // Place all significant initialization in InitInstance
  62. }
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // The one and only CHtbDdeApp object
  66. //
  67. CHtbDdeApp theApp;
  68.  
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // Defines
  72. //
  73. #define DLLEXPORT __declspec( dllexport )
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. /*
  77.     Function:        CHtbDdeApp::InitInstance
  78.  
  79.     Description:    
  80.  
  81.     Return type:    BOOL 
  82.  
  83.     Notes:
  84.         
  85. */
  86. BOOL CHtbDdeApp::InitInstance() 
  87. {
  88.     DdeInitialize();
  89.  
  90.     m_pClient = new CDdeClient;
  91.  
  92.     if (!m_pClient)
  93.     {
  94.         return FALSE;
  95.     }
  96.     else
  97.     {
  98.         return CWinApp::InitInstance();
  99.     }
  100. }
  101.  
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104. /*
  105.     Function:        CHtbDdeApp::ExitInstance
  106.  
  107.     Description:    
  108.  
  109.     Return type:    int 
  110.  
  111.     Notes:
  112.         
  113. */
  114. int CHtbDdeApp::ExitInstance() 
  115. {
  116.     if (m_pClient)
  117.     {
  118.         delete m_pClient;
  119.     }
  120.  
  121.     DdeCleanUp();
  122.     
  123.     return CWinApp::ExitInstance();
  124. }
  125.  
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128. // Exported Functions
  129. //
  130.  
  131. extern "C"
  132. {
  133.  
  134. /////////////////////////////////////////////////////////////////////////////
  135. /*
  136.     Function:        Ddeconnect
  137.  
  138.     Description:    Initiate a DDE conversation with a DDE Server
  139.  
  140.     Return type:    DWORD                    handle to the active DDE conversation
  141.                                                 or 0 if an error occurred
  142.     Argument:        char * szApplication    DDE application - see your app specific
  143.                                                 documenation
  144.     Argument:        char * szTopic            DDE topic - see your app specific
  145.                                                 documenation
  146.  
  147.     Notes:
  148.         
  149. */
  150. DLLEXPORT DWORD Ddeconnect(char * szApplication, char * szTopic)
  151. {
  152.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  153.  
  154.     CDdeConnection *pConnection;
  155.  
  156.     pConnection = theApp.m_pClient->MakeConnection("", szApplication, szTopic);
  157.  
  158.     if (!pConnection)
  159.     {
  160.         return 0L;
  161.     }
  162.  
  163.     return (DWORD)pConnection->m_hConv;
  164. }
  165.  
  166.  
  167. /////////////////////////////////////////////////////////////////////////////
  168. /*
  169.     Function:        Ddeterminate
  170.  
  171.     Description:    Terminate a DDE conversation
  172.  
  173.     Return type:    short
  174.     Argument:        DWORD hConv            handle to the DDE conversation
  175.  
  176.     Notes:
  177.         
  178. */
  179. DLLEXPORT short Ddeterminate(DWORD hConv)
  180. {
  181.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  182.  
  183.     CDdeConnection *pConnection;
  184.  
  185.     pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
  186.  
  187.     if (!pConnection)
  188.     {
  189.         return (short)FALSE;
  190.     }
  191.  
  192.     return (short)pConnection->Disconnect();
  193. }
  194.  
  195.  
  196. /////////////////////////////////////////////////////////////////////////////
  197. /*
  198.     Function:        Ddetimout
  199.  
  200.     Description:    Set the DDE timeout for this conversation
  201.  
  202.     Return type:    DWORD                returns the previous timeout value
  203.     Argument:        DWORD hConv            handle to the DDE conversation
  204.     Argument:        DWORD nTimeOut        the new timeout value
  205.  
  206.     Notes:
  207.         
  208. */
  209. DLLEXPORT DWORD Ddetimeout(DWORD hConv, DWORD nTimeOut)
  210. {
  211.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  212.  
  213.     CDdeConnection *pConnection;
  214.  
  215.     pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
  216.  
  217.     if (!pConnection)
  218.     {
  219.         return DEFAULT_TIMEOUT;
  220.     }
  221.  
  222.     return pConnection->SetTimeOut(nTimeOut);
  223. }
  224.  
  225.  
  226. /////////////////////////////////////////////////////////////////////////////
  227. /*
  228.     Function:        Ddeexecute
  229.  
  230.     Description:    Execute a specific command using an existing DDE conversation
  231.  
  232.     Return type:    short 
  233.     Argument:        DWORD hConv            handle to the DDE conversation
  234.     Argument:        char * szCommand
  235.  
  236.     Notes:
  237.         
  238. */
  239. DLLEXPORT short Ddeexecute(DWORD hConv, char * szCommand) 
  240. {
  241.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  242.  
  243.     CDdeConnection *pConnection;
  244.  
  245.     pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
  246.     
  247.     if (!pConnection)
  248.     {
  249.         return (short)FALSE;
  250.     }
  251.  
  252.     return (short)pConnection->Execute(szCommand);
  253. }
  254.  
  255.  
  256. /////////////////////////////////////////////////////////////////////////////
  257. /*
  258.     Function:        Dderequest
  259.  
  260.     Description:    Request information from a DDE Server
  261.  
  262.     Return type:    char * 
  263.     Argument:        DWORD hConv            handle to the DDE conversation
  264.     Argument:        char * szItem
  265.  
  266.     Notes:
  267.  
  268.         This impementation allows a char * return only.
  269.         
  270. */
  271. DLLEXPORT char * Dderequest(DWORD hConv, char * szItem)
  272. {
  273.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  274.  
  275.     int nSize;
  276.  
  277.     CDdeConnection *pConnection;
  278.  
  279.     pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
  280.  
  281.     if (!pConnection)
  282.     {
  283.         return "";
  284.     }
  285.  
  286.     return pConnection->Request(szItem, &nSize);
  287. }
  288.  
  289.  
  290. /////////////////////////////////////////////////////////////////////////////
  291. /*
  292.     Function:        Ddepoke
  293.  
  294.     Description:    Perform a DDE Poke
  295.  
  296.     Return type:    short 
  297.     Argument:        DWORD hConv            handle to the DDE conversation
  298.     Argument:        char * szItem
  299.     Argument:        char * szData
  300.  
  301.     Notes:
  302.         
  303. */
  304. DLLEXPORT short Ddepoke(DWORD hConv, char * szItem, char * szData)
  305. {
  306.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  307.  
  308.     CDdeConnection *pConnection;
  309.  
  310.     pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
  311.  
  312.     if (!pConnection)
  313.     {
  314.         return (short)FALSE;
  315.     }
  316.  
  317.     return (short)pConnection->Poke(szItem, szData, strlen(szData));
  318. }
  319.  
  320.  
  321. /////////////////////////////////////////////////////////////////////////////
  322. /*
  323.     Function:        Runexe
  324.  
  325.     Description:    Run a windows program
  326.  
  327.     Return type:    short 
  328.     Argument:        char *szExecutable
  329.     Argument:        short nCmdShow
  330.  
  331.     Notes:
  332.         
  333. */
  334. DLLEXPORT short Runexe(char *szExecutable, short nCmdShow)
  335. {
  336.     return (short)WinExec((const char *)szExecutable, nCmdShow);
  337. }
  338.  
  339. } // extern "C"